<h1 matDialogTitle>{{ 'Dataset Rollback From Snapshot' | translate }}</h1>
@if (isLoading) {
  <div mat-dialog-content class="loading">
    <mat-spinner [diameter]="40"></mat-spinner>
  </div>
} @else {
  @if (!wasDatasetRolledBack) {
    <form
      class="ix-form-container"
      [formGroup]="form"
      (submit)="onSubmit()"
    >
      <p
      [innerHTML]="
        'Use snapshot <i>{snapshot}</i> to roll <b>{dataset}</b> back to {datetime}?' | translate
          : {
              snapshot: publicSnapshot.snapshot_name,
              dataset: publicSnapshot.dataset,
              datetime: publicSnapshot.properties.creation.parsed.$date | formatDateTime
            }
        "
      ></p>

      <ix-fieldset>
        <ix-radio-group
          id="recursive"
          class="mt-field"
          [formControlName]="recursive.fcName"
          [label]="recursive.label | translate"
          [tooltip]="recursive.tooltip | translate"
          [options]="recursive.options"
        ></ix-radio-group>
      </ix-fieldset>

      <p
        [innerHTML]="'<b>WARNING:</b> Rolling the dataset back destroys data on the dataset <i>and</i> can destroy additional snapshots that are related to the dataset. <b>This can result in permanent data loss!</b> Do not roll back until all desired data and snapshots are backed up.' | translate"
      ></p>

      <div class="form-actions">
        <ix-checkbox
          [formControlName]="force.fcName"
          [label]="force.label"
          [required]="force.required"
        ></ix-checkbox>

        <div class="form-buttons">
          <button
            *ixRequiresRoles="requiredRoles"
            mat-button
            type="submit"
            color="primary"
            ixTest="rollback"
            [disabled]="form.invalid"
          >
            {{ 'Rollback' | translate }}
          </button>
          <button mat-button type="button" matDialogClose ixTest="cancel">
            {{ 'Cancel' | translate }}
          </button>
        </div>
      </div>
    </form>
  } @else {
    <p mat-dialog-content>
      {{ 'Dataset rolled back to snapshot {name}.' | translate: { name: publicSnapshot.snapshot_name } }}
    </p>

    <ix-form-actions mat-dialog-actions class="form-actions">
      <div class="form-buttons">
        <a
          mat-button
          type="submit"
          color="primary"
          ixTest="go-to-storage"
          matDialogClose
          [routerLink]="['/storage']"
        >
          {{ 'Go to Storage' | translate }}
        </a>

        <button mat-button type="button" matDialogClose ixTest="close">
          {{ 'Close' | translate }}
        </button>
      </div>
    </ix-form-actions>
  }
}


